<!doctype html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>型号sku管理</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">

    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="/webapp/js/common/jquery.global.settings.js"></script>

    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
    <div class="easyui-panel" style="border: none;">
        <div class="nav" id="nav"></div>
        <div class="easyui-panel" style="border:none;">
            <form id="ff">
                <div style="margin-bottom:20px;">
                    </select><label class="item-label">年份：</label>
                    <select class="easyui-combobox year" id="year"  name="year" data-options="panelHeight:'150'" style="width:6%;"></select>
                    <label id="label-for-month" class="item-label-wrap" style="margin-right: 0px;margin-left: 0.2%">月：<input type="text" class="easyui-combobox displayWM" id="month" name="month" style="width:53%; "/></label>
                    <label id="label-for-week" class="item-label-wrap" style="margin-right: 0px;margin-left: 0.2%">周：<input type="text" class="easyui-combobox displayWM" id="week" name="week" style="width:53%; "/></label>
                    <label class="item-label">型号码：</label>
                    <input class="easyui-textbox" id="modelCode" name="modelCode" style="width:100px">
                    <a href="javascript:void(0);" class="easyui-linkbutton c8" onclick="searchBy()" style="width:80px;margin-left: 40px;">查询</a>
                </div>
            </form>
        </div>
        <div class="table-wrapper">
            <table id="datagrid" class="easyui-datagrid" data-options="fitColumns:true,scrollbarSize:0,striped:true" style="max-height: 708px;">
                <thead>
                <tr>
                    <th field="ck" checkbox="true"></th>
                    <th data-options="field:'year',align:'center'" width="30">年</th>
                    <th data-options="field:'month',align:'center'" width="25">月</th>
                    <th data-options="field:'week',align:'center'" width="25">周</th>
                    <th data-options="field:'modelCode',align:'center'" width="40">型号码</th>
                    <th data-options="field:'sku',align:'center'" width="200">sku</th>
                    <th data-options="field:'originalModel',align:'center'" width="200">标题</th>

                    <th data-options="field:'modelName',align:'center'" width="70">型号名</th>
                    <th data-options="field:'parentName',align:'center'" width="70">父型号名</th>

                    <th data-options="field:'action',align:'center',formatter:actions" width="90">操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var queryModelCode = getQueryParameter("modelCode");
    function initPage() {
        setNav();
        //根据当前模式和月份周切换月与周
        if (isMonthType()) {
            $("#label-week").remove();
        } else {
            $("#label-month").remove();
        }
        initMonthWeek("label-for-month", "label-for-week");

        if (queryModelCode) {
            $("#modelCode").textbox('setValue', queryModelCode);
            searchBy(1,100);
        }
    }
    $(function(){
        $("#datagrid").datagrid({
            rownumbers: true,
            pagination:true,
            idField:"id",
            checkOnSelect:false,
            pageSize: 100,
            pageList: [100, 300, 500],
            emptyMsg:"暂无数据",
            toolbar:"#th",
            onLoadSuccess:function (data) {
                //不加这个，跳转到下一页的时候，之前的复选框不会清除掉
                $("#datagrid").datagrid("clearChecked");
            },
        }).datagrid("getPager").pagination({
            onSelectPage:searchBy
        });
        initPage();
    });

    function searchBy(page,size) {
        var data = {};
        data.reportType = window.parent.workMode.toUpperCase();
        data.year = $("#year").combobox('getValue');
        if ($("#week").is("*")) {
            data.week = $("#week").combobox('getValue');
        }else {
            data.month = $("#month").combobox('getValue');
        }
        data.modelCode=$("#modelCode").textbox('getValue');
        if (!data.modelCode) {
            $.messager.alert("提示", "请输入型号码！",'info');
            return;
        }
        //分页参数
        var pagination  = $("#datagrid").datagrid('getPager').data('pagination').options;
        data.pageNumber = pagination.pageNumber;
        data.pageSize = pagination.pageSize;
        $.ajax({
            url:config.url + "/sku/queryModelSkuList",
            type:'post',
            data:JSON.stringify(data),
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
            },
            complete:function () {
                $.messager.progress("close");
            },
            success:function (data) {
                $.messager.progress("close");
                if (data.code != 200) {
                    $.messager.alert("提示",data.msg, "error");
                    return;
                }
                if (data.data) {
                    // $("#datagrid").datagrid("loadData",data.data);
                    let list = data.data.list == null ? [] : data.data.list;
                    $("#datagrid").datagrid("loadData", {total:data.data.size, rows: list});
                }
            },
            error:function (XMLHttpRequest,textStatus,errorThrown) {

            }
        });
    }

    function actions(val, row){
        return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
            "style='width:60px;' onclick='edit(\""+row.modelId+"\",\""+row.categoryCode+"\")'>修改</a>&nbsp;&nbsp;"+
            "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
            "style='width:60px;' onclick='add(\""+row.categoryCode+"\")'>新增</a>&nbsp;&nbsp;"
    }

    function edit(id,categoryCode){
        window.parent.addTab("修改型号", "/webapp/pages/product/model/add.html?id="+id+"&categoryCode="+categoryCode);
    }

    function add(categoryCode){
        window.parent.addTab("新增型号", "/webapp/pages/product/model/add.html?categoryCode="+categoryCode);
    }
</script>
</html>
